package me.tuyou.es.java.controller;

import me.tuyou.es.java.dto.Hotel;
import me.tuyou.es.java.service.EsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class TestController {

    @Autowired
    private EsService esService;

    @GetMapping("/test")
    public String getRec() {
        List<Hotel> hotelList = esService.getHotelFromTitle("再来");
        return CollectionUtils.isEmpty(hotelList) ? "no data" : hotelList.toString();
    }

    @PutMapping("/createDoc")
    public String createDoc() throws IOException {
        Map<String, Object> dataMap = new HashMap<>();
        dataMap.put("title", "华兴酒店");
        dataMap.put("price", 120);
        dataMap.put("city", "成都");
        esService.singleIndexDoc(dataMap, "hotel", "006");
        return "success";
    }
}
